package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	Name     string `json:"name"`          //一定是双引号
	Age      int    `json:"old,omitempty"` //omitempty空值省略
	Password string `json:"-"`             //-表示不输出
}

func main() {
	s := Student{
		Name:     "枫枫",
		Age:      0,
		Password: "123456",
	}
	byteData, _ := json.Marshal(s)
	fmt.Println(string(byteData)) // {"name":"枫枫","age":21}
}
